/*
 * PriceUtils.java
 * business
 *
 * Created by ChenTao on 2016/9/9.
 *
 * Copyright (c) 2016年 yidiandao. All rights reserved.
 */

package com.yidiandao.business.utils;

import android.graphics.drawable.Drawable;
import android.widget.TextView;

import com.yidiandao.business.R;

import static com.yidiandao.business.utils.UIUtils.getResources;

/**
 * 价格显示工具.
 */
public class PriceUtils {

    /**
     * 判断用户是否登录
     */
    public static boolean isLogin() {
        return !PreferenceUtils.STRING_DEFAULT.equals(PreferenceUtils.getToken(UIUtils.getContext()));
    }

    /**
     * 商品详情里的昨日比价
     *
     * @param status 标识符号 "-1" 下调 "0" 平稳 "1" 上升
     */
    public static void setGoodsDetailChargeChange(TextView view, String status) {
        String text = null;
        int color = 0;
        Drawable drawable = null;
        switch (status) {
            case "-1":
                text = UIUtils.getString(R.string.goodsdetail_down);
                color = UIUtils.getColor(R.color.text_down);
                drawable = getResources().getDrawable(R.mipmap.ic_charge_down);
                break;
            case "0":
                text = UIUtils.getString(R.string.goodsdetail_unchange);
                color = UIUtils.getColor(R.color.text_unchange);
                drawable = getResources().getDrawable(R.mipmap.ic_charge_unchange);
                break;
            case "1":
                text = UIUtils.getString(R.string.goodsdetail_up);
                color = UIUtils.getColor(R.color.text_up);
                drawable = getResources().getDrawable(R.mipmap.ic_charge_up);
                break;
        }
        view.setText(text);
        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight()); //设置边界
        view.setCompoundDrawables(null, null, drawable, null); //画在右边
        view.setTextColor(color);
    }


    public static void setDailyPrice(TextView view, float price) {
        String text = null;
        int color = 0;
        Drawable drawable = null;

        if (price < 0) {
            price = -price;
            text = UIUtils.getResources().getString(R.string.down, price + "");
            color = UIUtils.getColor(R.color.text_down);
            drawable = UIUtils.getResources().getDrawable(R.mipmap.ic_decline_big);
        } else if (price == 0) {
            text = UIUtils.getResources().getString(R.string.hold);
            color = UIUtils.getColor(R.color.text_unchange);
            drawable = UIUtils.getResources().getDrawable(R.mipmap.ic_hold_big);
        } else {
            text = UIUtils.getResources().getString(R.string.up, price + "");
            color = UIUtils.getColor(R.color.text_up);
            drawable = UIUtils.getResources().getDrawable(R.mipmap.ic_rise_big);
        }
        view.setText(text);
        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight()); //设置边界
        view.setCompoundDrawables(drawable, null, null, null);
        view.setTextColor(color);
    }

    /**
     * 商品相关评价
     */
    public static void setShopValueChange(TextView view, float value) {
        int color = 0;
        Drawable drawable = null;
        switch (RatingUtils.getShopRating(value)) {
            case "-1":
                color = UIUtils.getColor(R.color.text_down);
                drawable = getResources().getDrawable(R.mipmap.ic_charge_down);
                break;
            case "0":
                color = UIUtils.getColor(R.color.text_unchange);
                drawable = getResources().getDrawable(R.mipmap.ic_charge_unchange);
                break;
            case "1":
                color = UIUtils.getColor(R.color.text_up);
                drawable = getResources().getDrawable(R.mipmap.ic_charge_up);
                break;
        }
        view.setText(value + "");
        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight()); //设置边界
        view.setCompoundDrawables(null, null, drawable, null); //画在右边
        view.setTextColor(color);
    }

//    public static float getTotalPriceBeforeCalculatePayWay(
//            QueryConfirmOrderResponse.TotalFee totalFee) {
//        return totalFee.getGoodsTotalPrice()
//                - totalFee.getRedPaper()
//                + totalFee.getInvoice()
//                + totalFee.getShipping();
//    }
//
//    public static QueryConfirmOrderResponse.TotalFee calculatePayWayMoney(
//            QueryConfirmOrderResponse.TotalFee totalFee, PayWay payWay) {
//
//        // 选择支付方式的总费用
//        float submitMoneyBeforeCalculatePayWay = totalFee.getSubmitMoneyBeforeCalculatePayWay();
//
//        // 支付费率
//        float payFee = payWay.getPayFee();
//        // 支付手续费上线 (无上线为-1)
//        float upperLimit = payWay.getUpperLimit();
//
//        float payWayMoney;
//        if (upperLimit == PayWay.UN_LIMITED) {
//            // 无上限
//            payWayMoney = submitMoneyBeforeCalculatePayWay * payFee;
//        } else {
//            payWayMoney = submitMoneyBeforeCalculatePayWay * payFee > upperLimit ? upperLimit
//                    : submitMoneyBeforeCalculatePayWay * payFee;
//        }
//
//        LogUtils.w("rate : before --->" + payWayMoney);
//
//        // 最终价格保留到小数点后两位
//        payWayMoney = NumberFormatUtils.get2DecimalFloatValue(payWayMoney);
//
//        LogUtils.w("rate : after --->" + payWayMoney);
//
//        totalFee.setPayWayMoney(payWayMoney);
//        totalFee.setFinalMoney(payWayMoney + submitMoneyBeforeCalculatePayWay);
//
//
//        return totalFee;
//    }
}
